var years = []
var month = {}
var day = {}
var hours = []
var minutes = []
var seconds = []

// init year array
const date = new Date()
years = [
  {
    text: date.getFullYear(),
    value: 'y' + date.getFullYear()
  },
  {
    text: date.getFullYear() + 1,
    value: 'y' + (date.getFullYear() + 1)
  }
]

// init month object
const arraym1 = []
for (let i = 1; i <= 12; i++) {
  const m = {
    text: PrefixInteger(i, 2),
    value: 'm1' + i
  }
  arraym1.push(m)
}
month['y' + date.getFullYear()] = arraym1
const arraym2 = []
for (let i = 1; i <= 12; i++) {
  const m = {
    text: PrefixInteger(i, 2),
    value: 'm2' + i
  }
  arraym2.push(m)
}
month['y' + (date.getFullYear() + 1)] = arraym2

// init day object
for (let i = 1; i <= 12; i++) {
  const days1 = fanDayByYearMonth(date.getFullYear(), i)
  const arrayday1 = []
  for (let j = 1; j <= days1; j++) {
    const d = {
      text: PrefixInteger(j, 2),
      value: 'd' + j
    }
    arrayday1.push(d)
  }
  day['m1' + i] = arrayday1
  const days2 = fanDayByYearMonth(date.getFullYear() + 1, i)
  const arrayday2 = []
  for (let j = 1; j <= days2; j++) {
    const d = {
      text: PrefixInteger(j, 2),
      value: 'd' + j
    }
    arrayday2.push(d)
  }
  day['m2' + i] = arrayday2
}

// init hours array
for (let i = 0; i <= 23; i++) {
  const h = {
    text: PrefixInteger(i, 2),
    value: 'h' + i
  }
  hours.push(h)
}

// init minutes array
for (let i = 0; i <= 59; i++) {
  const m = {
    text: PrefixInteger(i, 2),
    value: 'm' + i
  }
  minutes.push(m)
}

// init seconds array
for (let i = 0; i <= 59; i++) {
  const s = {
    text: PrefixInteger(i, 2),
    value: 's' + i
  }
  seconds.push(s)
}

// 个位补0
function PrefixInteger(num, length) {
  return (Array(length).join('0') + num).slice(-length)
}
// 获取某年某月有多少天
function fanDayByYearMonth(year, month) {
  switch (month) {
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
      return 31
      break
    case 2:
      return isRunYears(year) ? 29 : 28
      break
    case 4:
    case 6:
    case 9:
    case 11:
      return 30
      break
  }
}
// 被四整除（不被100整除）的是闰年，其中可以被100整除的同时必须被400整除的才是闰年，其余的就是平年
function isRunYears(year) {
  return year % 4 == 0 ? (year % 100 == 0 ? (year % 400 == 0) : true) : false
}

export { years, month, day, hours, minutes, seconds }
